package org.huangrui.javase.thread.Interrupt;

/**
 * @Author hr
 * @Create 2025-11-08 14:55
 **/
public class T01InterruptOrStop {
    public static void main(String[] args) throws InterruptedException {
        // interruptThread();

    }

    private static void interruptThread() throws InterruptedException {
        Thread worker = new Thread(() -> {
            while (true) {
                if (!Thread.currentThread().isInterrupted()) {
                    System.out.println("Worker thread is running");
                } else {
                    System.out.println("Worker clear...");
                    break;
                }
            }
            System.out.println("Worker thread is exiting");
        });

        worker.start();

        // 主线程等待一段时间后中断工作线程
        Thread.sleep(1);
        // 中断工作线程
        worker.interrupt();
    }
}
